<template>
  <div>
    <BaseModal @onClose="onClose" :show="show" title="添加题目">
      <Searchbar>
        <el-input @change="getList" v-model="search.course_name" placeholder="请输入课程名称"></el-input>
        <el-autocomplete
          class="inline-input"
          v-model="selectedKld"
          :fetch-suggestions="queryKld"
          placeholder="请输入知识点"
          @select="selectKld"
        ></el-autocomplete>
      </Searchbar>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="question_name" label="题目名称" ></el-table-column>
        <el-table-column prop="knowledges" label="关联知识点" ></el-table-column>
        <el-table-column prop="question_type_label" label="题目类型" ></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="onSubmit(scope.row)" size="small" class="text-warning">添加</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        layout="prev, pager, next, jumper"
        @current-change="handleCurrentChange"
      @size-change=handleSizeChange
        :current-page.sync="search.page"
        :page-size="search.page_size"
        :total="total"
      ></el-pagination>
    </BaseModal>
  </div>
</template>
<script>
import pageMixin from "@/mixins/pageMixin";
import BaseModal from "@/modals/PureModal";
import CreateFilter from "@/mixins/CreateFilter";
import { queModel } from "@/api/models";
import selectChange from '@/mixins/selectionChang.js';
import Searchbar from '@/components/Searchbar';
export default {
  mixins: [pageMixin, CreateFilter, selectChange],
  components: {BaseModal, Searchbar},
  data() {
    return {
      total: 0,
      tableData: [],
      search: {
        page: 1,
        page_size: 10,
        course_name: '',
        knowledge: null
      }
    };
  },
  props: {
    question_type: {
      type: [String],
      default: null
    },
    show: {
      type: Boolean,
      default: false
    }
  },
  mounted() {
    this.getList();
  },
  watch: {
    show (newVla) {
      if(newVla)
        this.getList();
    }
  },
  methods: {
    onClose() {
      this.$emit("onClose");
    },
    onSubmit(row) {
      this.$emit('onSubmit', row.id);
    },
    getList() {
      this.search.question_type = this.question_type
      queModel.list(this.search,res => {
        console.log(res)
        this.tableData = res.data.map((v) => {
          v.question_type_label = this.question_typeToLabel(v.question_type);
          return v;
        });
        this.total = res.total_records;
        
      })
    }
  }
};
</script>
<style scoped lang="scss">
  
</style>